#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int n,m,L,V;
int d[maxn],v[maxn],a[maxn];
int p[maxn];
void solve()
{
    cin>>n>>m>>L>>V;
    //cout<<n<<" "<<m<<" "<<" "<<L<<" "<<V<<" ";
    int dengyu=0,xiaoyu=0;
    for(int i = 1;i <= n;i++)
    {
        cin>>d[i]>>v[i]>>a[i];
        if(a[i] < 0) xiaoyu++;
        if(a[i] == 0) dengyu++;
    }
    int faest = 0;
    for(int i = 1;i <= m;i++)
    {
        cin>>p[i];
        faest = max(faest,p[i]);
    }

    if(dengyu == n)
    {
        int ans1 = 0;
        for(int i = 1;i <= n;i++)
        {
            if(v[i] > V && faest >= d[i]) ans1++;
        }
        int ans2;
        if(ans1 == 0) ans2 = m;
        else ans2 = m-1;
        cout<<ans1<<" "<<ans2<<'\n';
        return;
    }

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    int T;cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}
